package com.xh.lesson.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xh.lesson.entity.TManageDepart;
import com.xh.lesson.exception.BusinessException;
import com.xh.lesson.exception.code.BaseResponseCode;
import com.xh.lesson.mapper.TManageDepartdMapper;
import com.xh.lesson.service.TManageDepartService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 柴&许
 * @since 2021-06-23
 */
@Service
public class TManageDepartServiceImpl extends ServiceImpl<TManageDepartdMapper, TManageDepart> implements TManageDepartService {
    //查询所有部门
    //根据id查询管理部门（一级）
    @Override
    public String selectnameByid(Integer id) {
        String departname = baseMapper.selectById(id).getDepartname();
        return departname;
    }
    //根据id调配使用部门（二级）
    @Override
    public String selectPnameByid(Integer id) {
        Integer deployid = baseMapper.selectById(id).getDeployid();
        if (deployid == 0) {
            throw new BusinessException(BaseResponseCode.DATA_ERROR);
        }
        String departname = baseMapper.selectById(deployid).getDepartname();
        return departname;
    }

    @Override
    public List<TManageDepart> selectnameBypid() {
        List<TManageDepart> tManageDeparts = baseMapper.selectDepartnameByDeployid();

        return tManageDeparts;
    }

}
